package com.lolongmaps.main;

import com.lolongmaps.main.WeatherConnector;
import com.lolongmaps.test.R;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class HomeScreenView extends Activity implements OnClickListener {

	ImageButton eat, about, help;
	Boolean connected;
	WeatherConnector weatherConnector;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.homescreen);

		eat = (ImageButton) findViewById(R.id.homescreenButtonEat);
		eat.setOnClickListener(this);

		help = (ImageButton) findViewById(R.id.homescreenButtonHelp);
		help.setOnClickListener(this);

		about = (ImageButton) findViewById(R.id.homescreenButtonAbout);
		about.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.homescreenButtonEat:
			Intent pricePage = new Intent("com.lolongmaps.main.STARTVIEW");
			startActivity(pricePage);
			break;

		case R.id.homescreenButtonHelp:
			Intent helpPage = new Intent("com.lolongmaps.main.HELPVIEW");
			startActivity(helpPage);
			break;

		case R.id.homescreenButtonAbout:
			Intent aboutPage = new Intent("com.lolongmaps.main.ABOUTVIEW");
			startActivity(aboutPage);
			break;
		}

	}

	// Checks connection *Don't forget to add
	// android.permission.ACCESS_NETWORK_STATE
	public boolean checkConn(Context ctx) {

		ConnectivityManager conMgr = (ConnectivityManager) ctx
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo i = conMgr.getActiveNetworkInfo();

		if (i == null)
			return false;
		if (!i.isConnected())
			return false;
		if (!i.isAvailable())
			return false;

		return true;

	}

//	@Override
//	public void onBackPressed() {
//
//		// Set if connected
//		connected = checkConn(HomeScreenView.this);
//
//		if (connected) {
//
//			weatherConnector = new WeatherConnector();
//
//			AlertDialog.Builder builder = new AlertDialog.Builder(this);
//			builder.setMessage(
//					weatherConnector.returnSuggestion()
//							+ " Thanks for trusting me. ;)")
//					.setCancelable(false)
//					.setNegativeButton("Ok",
//							new DialogInterface.OnClickListener() {
//
//								public void onClick(DialogInterface dialog,
//										int id) {
//									HomeScreenView.this.finish();
//								}
//							});
//
//			AlertDialog alert = builder.create();
//			alert.show();
//
//		} else {
//
//			AlertDialog.Builder builder = new AlertDialog.Builder(this);
//			builder.setMessage(
//					"It appaers that you don't have an internet connection. Sorry, I can't provide clothign suggestion. :(")
//					.setCancelable(false)
//					.setNegativeButton("Ok",
//							new DialogInterface.OnClickListener() {
//
//								public void onClick(DialogInterface dialog,
//										int id) {
//									HomeScreenView.this.finish();
//								}
//							});
//
//			AlertDialog alert = builder.create();
//			alert.show();
//		}
//	}
}
